package com.newtouch.avmarketing.mongo.controller;

import com.newtouch.avmarketing.mgr.modules.avmarkrting.model.Result;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.model.ResultCodes;
import com.newtouch.avmarketing.mongo.po.PolicyPo;
import com.newtouch.avmarketing.mongo.service.InsurancePolicyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/policy")
@Slf4j
@Api(tags = "001 后台双录数据填充（保单对象）")
public class PolicyController {

    @Autowired
    private InsurancePolicyService policyService;

    @ApiOperation("查询保单")
    @PostMapping("/queryPolicy")
    public Result queryPolicyCode(String policyCode){
        try {
            PolicyPo policyPo = policyService.findPolicy(policyCode);
            if (policyPo!=null){
                return Result.of(ResultCodes.SUCCESS_CODE,"查询保单成功",policyPo);
            }else {
                return Result.of(ResultCodes.ERROR_CODE,"保单数据为空");
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("查询保单失败",e);
        }
        return Result.of(ResultCodes.ERROR_CODE,"查询保单失败");
    }
}
